import { distance } from '../../utils/util.js'

Component({

  properties: {
    name : {
      type : String,
      value : ''
    },
    address: {
      type: String,
      value: ''
    },

    dst : {
      type : Array,
      value : []
    },

    src: {
      type: Array,
      value: []
    }
  },

  observers: {
    dst(dst) {
      this.calculate()
    },

    src(src) {
      this.calculate()
    }
  },

  data: {
    distance : ''
  },

  methods: {
    calculate () {
      let dst = this.properties.dst
      let src = this.properties.src
      if(dst.length == 0 || src.length == 0){
        return
      }
      let v = distance(dst, src)
      this.setData({ distance: v})
    },

    nav () {
      let dst = this.properties.dst
      wx.openLocation({
        longitude: dst[0],
        latitude: dst[1],
        name: this.properties.name,
        address: this.properties.address
      })
    }
  }
})
